<%= render "shared/admin/credit_links"%>

<h2>积分订单管理</h2>
<%=form_with(path: admin_credit_variant_orders_path,local: true, method: "get") do |f|%>
  <div class='tw-gap-4 tw-grid tw-grid-cols-4'>
    <div class="form-groups">
      <%=f.label :uuid_eq, "订单号"%>
      <%=f.text_field :uuid_eq, value: params[:uuid_eq],  class: "form-control"%>
    </div>

    <div class="form-groups">
      <%=f.label :credit_product_category_eq, "商品类型"%>
      <%= f.select :credit_product_category_eq, %w[实物 虚拟物品], {include_blank: true, selected: params[:credit_product_category_eq]}, {class: "form-control"} %>
    </div>

    <div class="form-groups">
      <%=f.label :status_eq, "订单状态"%>
      <%= f.select :status_eq, CreditVariantOrder.aasm(:status).states.map{|x| [I18n.t("activerecord.enums.credit_variant_order.status.#{x.name}"), x.name]}, {include_blank: true, selected: params[:status_eq]}, {class: "form-control"} %>
    </div>
    <div class="form-groups">
      <%=f.label :user_login_eq, "用户名称"%>
      <%=f.text_field :user_login_eq, value: params[:user_login_eq], class: "form-control"%>
    </div>
    <div class="form-groups">
      <%=f.label :user_email_eq, "用户email"%>
      <%=f.text_field :user_email_eq, value: params[:user_email_eq], class: "form-control"%>
    </div>
    <div class="form-groups">
      <%=f.label :uuid_eq, "订单号"%>
      <%=f.text_field :uuid_eq, value: params[:uuid_eq],  class: "form-control"%>
    </div>
    <div class="form-groups">
      <%=f.label :credit_variant_sku_eq, "SKU"%>
      <%=f.text_field :credit_variant_sku_eq, value: params[:credit_variant_sku_eq],  class: "form-control"%>
    </div>
    <div class="form-groups">
      <%=f.label :credit_product_uuid_eq, "商品UUID"%>
      <%=f.text_field :credit_product_uuid_eq, value: params[:credit_product_uuid_eq],  class: "form-control"%>
    </div>
    <div class="tw-col-start-1 tw-row-span-2 form-groups">
      <%=f.label :created_at_gteq, "订单区间"%>
      <div class="tw-flex">
        <%=f.datetime_field :created_at_gteq, value: params[:created_at_gteq],  class: "form-control"%>
        <%=f.datetime_field :created_at_lteq, value: params[:created_at_lteq],  class: "form-control"%>
      </div>
    </div>
  </div>
  <div class="tw-items-center tw-py-5 tw-flex tw-space-x-3">
    <%=f.submit "搜索", class: "btn btn-primary"%>
    <%= link_to "重置搜索", admin_credit_variant_orders_path %>
  </div>
<%end%>
<table class="table">
  <thead>
    <tr>
      <th>用户</th>
      <th>商品名</th>
      <th>具体型号</th>
      <th>个数</th>
      <th>交易价格</th>
      <th>状态</th>
      <th>时间</th>
      <th>操作</th>
    </tr>
  </thead>
  <tbody>
    <%@credit_variant_orders.includes(:credit_variant, :credit_product).each do |order|%>
      <tr>
        <td>
          <%= link_to params.permit!.merge(user_login_eq: order.user.login) do %>
            <%= order.user.login %>
          <%end %>
        </td>
        <td><%= order.credit_product.title %></td>
        <td><%= order.credit_variant.title %></td>
        <td><%= order.num %></td>
        <td>
          <span><%= order.credit_price.to_i * order.num %></span>
          <span>(<%= order.credit_price.to_i %> )</span>
        </td>
        <td>
          <%= link_to params.permit!.merge(status_eq: order.status) do %>
            <%= I18n.t("activerecord.enums.credit_variant_order.status.#{order.status}")  %>
          <% end %>
        </td>
        <td><%= order.created_at %></td>
        <td><%= link_to "详情", admin_credit_variant_order_path(order.id), target: "_blank" %></td>
      </tr>
    <%end%>
  </tbody>
</table>

<%=paginate @credit_variant_orders%>
